package be.ipl.servlet;

import java.io.IOException;
import java.util.List;

import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import be.ipl.domaine.Partie;
import be.ipl.ucc.GestionJoueur;
import be.ipl.ucc.GestionParties;

/**
 * Servlet implementation class Actualiser
 */
@WebServlet(name = "actualiser.html")
public class Actualiser extends HttpServlet {
	private static final long serialVersionUID = 1L;

	@EJB
	private GestionJoueur joueur;
	@EJB
	private GestionParties gestiondeparties;

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		List<Partie> liste = gestiondeparties.listerPartiesARejoindre();
		request.setAttribute("liste", liste);
		System.out.println("Nombre partie dans liste :" +liste.size());

		HttpSession session = request.getSession();
		String login = null;
		synchronized (session) {
			login = (String) session.getAttribute("login");
		}
		request.setAttribute("login", login);

		List<Partie> liste2 = gestiondeparties.listerPartiesAReprendre(login);
		request.setAttribute("liste2", liste2);

		getServletContext().getNamedDispatcher("accueil.html").forward(request,
				response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
